/*
    This file is part of Raptor.

    Raptor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Raptor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Raptor.  If not, see <http://www.gnu.org/licenses/>.

 */

#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H

#include <QDialog>
#include <QPointer>

class QListWidget;
class QListWidgetItem;
class QStackedWidget;
class QLineEdit;
class Raptor;
class QGroupBox;
class QLabel;
class QComboBox;
class QSpinBox;
class QGridLayout;
class QVBoxLayout;
class QHBoxLayout;
class QCheckBox;

class settingsPage;
class hosterPage;

class configDialog : public QDialog
{
	Q_OBJECT

	public:
		configDialog(QPointer<Raptor> r);

	public slots:
		void changePage(QListWidgetItem *current, QListWidgetItem *previous);

	private:
		void createIcons();

		QPointer<Raptor> raptor;

		QPointer<QListWidget> contentsWidget;
		QPointer<QStackedWidget> pagesWidget;

		settingsPage *pageSettings;
		hosterPage *pageHoster;

	private slots:
		void slot_finishButton_accept();
};

class settingsPage : public QWidget
{
	Q_OBJECT

	public:
		settingsPage(QPointer<Raptor> r);
		~settingsPage();

	private:
		QPointer<Raptor> raptor;

		QPointer<QGridLayout> mainLayout;
		QPointer<QGridLayout> groupLayout;

		QPointer<QGroupBox> configGroup;

                QPointer<QLabel> raptorFolderLabel;
                QPointer<QPushButton> raptorFolderButton;
                QPointer<QLineEdit> raptorFolder;

                QPointer<QLabel> downloadFolderLabel;
                QPointer<QPushButton> downloadFolderButton;
                QPointer<QLineEdit> downloadFolder;

		QPointer<QLabel> proxyLabel1;
		QPointer<QLabel> proxyLabel2;
		QPointer<QLineEdit> proxyHost;
		QPointer<QSpinBox> proxyPort;
		QPointer<QComboBox> proxyType;
		QPointer<QLineEdit> proxyUser;
		QPointer<QLineEdit> proxyPass;

		QPointer<QCheckBox> sslCheckBox;

		QPointer<QLabel> maxDownloadsLabel;
		QPointer<QSpinBox> maxDownloadsSpinBox;

		QPointer<QPushButton> applyButton;

	private slots:
		void slot_applyButton_clicked();

                void slot_raptorFolderButton_clicked();
                void slot_downloadFolderButton_clicked();
};

class hosterPage : public QWidget
{
	Q_OBJECT

	public:
		hosterPage(QPointer<Raptor> r);
		~hosterPage();

	private:
		QPointer<Raptor> raptor;

		QPointer<QGridLayout> mainLayout;
		QPointer<QGridLayout> groupLayout;

		QPointer<QPushButton> applyButton;

		QPointer<QGroupBox> configGroup;
		QPointer<QLabel> hosterLabel;
		QPointer<QComboBox> hosterCombo;

		QPointer<QLabel> authLabel;
		QPointer<QLineEdit> authUser;
		QPointer<QLineEdit> authPass;
		QPointer<QPushButton> authLogin;
		QPointer<QPushButton> authDelete;

		QPointer<QLabel> maxDownloadsLabel;
		QPointer<QSpinBox> maxDownloadsSpinBox;

		void loadHosterSettings(const int &hoster);

	private slots:
		void slot_hosterCombo_currentIndexChanged(const QString &text);
		void slot_applyButton_clicked();
		void slot_authLoginButton_clicked();
		void slot_authDeleteButton_clicked();

		void slot_raptor_hosterLoginFinished(const bool error);
};

#endif
